/*
============================================================================
 Name			: BlueToothServiceSearcher.h
 Author	  		: 
 Copyright   	: 
 Description 	: CBluetoothServiceSearcher is responsible for finding out if a remote device supports
 				  a specific BT service.
============================================================================
*/

#ifndef __BLUETOOTHSERVICESEARCHER_H__
#define __BLUETOOTHSERVICESEARCHER_H__

// INCLUDES
#include <e32base.h>
#include <bttypes.h>
#include <bt_sock.h>
#include <btsdp.h>
#include "BluetoothConnector.h"
#include "CommonInterfaces.h"


// CLASS DECLARATION
/**
* CBluetoothServiceSearcher
* Search for the presence of a specific BT service on a remote BT device
*/
class CBluetoothServiceSearcher : public CBase, public MSdpAgentNotifier, public MSdpAttributeValueVisitor
    {
public:
	/**
	* Constructor
	* @param aObs	Interface to report to the caller the service search status
	*/
    CBluetoothServiceSearcher(MBluetoothServiceSearcherObserver& aObs);
    
	/**
	* Destructor
	*/
	~CBluetoothServiceSearcher();
	
	/**
	* Retrives from a remote device a SDP's service record. On completion call NextRecordRequestComplete()
	* @param aTarget	The remote BT device address	
	* @param aUUID		The BT's service UUID (RPS's service UUID) 
	*/
	void FindServiceByUUIDL(const TBTDevAddr& aTarget,const TUUID& aUUID);

private:
	// from MSdpAgentNotifier
	/**
	* Called when a service record request (CSdpAgent::NextRecordRequestComplete()) operation completes
	* @param aError		KErrNone if successful; KErrEof if there are no more SDP records left to be read; or an SDP error			
	* @param aHandle	Service record for which the query was made				
	* @param aTotalRecordsCount		Total number of matching records 		
	*/
	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount);
	
	/**
	* Called when an attribute request (CSdpAgent::AttributeRequestL()) wants to pass up a result
	* @param aHandle 	Service record for which the query was made	
	* @param aAttrID	ID of the attribute obtained
	* @param aAttrValue	Attribute value obtained
	*/
	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue);
	
	/**
	* Called when an attribute request (CSdpAgent::AttributeRequestL()) wants to signal the completion of an attribute request
	* @param aHandle	Service record for which the query was made	
	* @param aError		An error	
	*/
	virtual void AttributeRequestComplete(TSdpServRecordHandle aHandle, TInt aError);
	
	//From MSdpAttributeValueVisitor
	/**
	* Called to pass an attribute value
	* @param aValue Attribute value
	* @param aType Value type
	*/
    void VisitAttributeValueL(CSdpAttrValue& aValue, TSdpElementType aType);
    
	/**
	* Called to indicate the start of a list of attribute values
	* @param aList Attribute value list
	*/
    void StartListL(CSdpAttrValueList& aList);
    
	/**
	* Called to indicate the end of a list of attribute values
	*/
    void EndListL();
    
private:
	/**
	* A reference to the Service Searcher Observer
	*/
	MBluetoothServiceSearcherObserver&	iObserver;
	
	/**
	* Makes Bluetooth service discovery protocol (SDP) requests to a remote BT device
	*/
	CSdpAgent* iAgent;
	
	/**
	* Holds a list of Universal Unique Identifiers (UUIDs), to be matched in SDP Service Search Requests
	*/
	CSdpSearchPattern* iSdpSearchPattern;
		
	/**
	* RFCOMM's port
	*/
	TInt iPort;
	
	/**
	* True if the record contains the RFCOMM attribute
	*/
	TBool iFoundRfcommProtocol;
	};


#endif //__BLUETOOTHSERVICESEARCHER_H__

